package com.priox.sigar.application.job.mappers;

import com.priox.sigar.client.dto.CuentaContableDTO;
import org.apache.commons.lang.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindException;

/**
 * User: Matrix
 * Date: 10/02/13
 */
@Component
public class CuentaContableFieldSetMapper implements FieldSetMapper<CuentaContableDTO> {
    private static final Logger LOGGER = LoggerFactory.getLogger(CuentaContableFieldSetMapper.class);

    /*
     * (non-Javadoc)
     *
     * @see
     * org.springframework.batch.item.file.mapping.FieldSetMapper#mapFieldSet
     * (org.springframework.batch.item.file.transform.FieldSet)
     */
    @Override
    public CuentaContableDTO mapFieldSet(FieldSet fieldSet) throws BindException {
        CuentaContableDTO result = new CuentaContableDTO();
        if (NumberUtils.isNumber(fieldSet.readString(0))) {
            result.setDescripcion((fieldSet.readString(1)));
            result.setCuentaContableId(fieldSet.readString(0));
        }
        return result;
    }
}

